package org.wtj.service.sys;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.wtj.entity.ResponsePageEntity;
import org.wtj.entity.sys.SysUserRoleConditionEntity;
import org.wtj.entity.sys.SysUserRoleEntity;
import org.wtj.mapper.BaseMapper;
import org.wtj.mapper.sys.SysUserRoleMapper;
import org.wtj.service.BaseService;

import java.util.List;

/**
 * 用户角色关联 服务层
 *
 * @author wang 该项目是知识星球：java突击队 的内部项目
 * @date 2025-03-06 21:50:53
 */
@Service
public class SysUserRoleService extends BaseService<SysUserRoleEntity, SysUserRoleConditionEntity> {

	@Autowired
	private SysUserRoleMapper sysUserRoleMapper;

	/**
     * 查询用户角色关联信息
     *
     * @param id 用户角色关联ID
     * @return 用户角色关联信息
     */
	public SysUserRoleEntity findById(Long id) {
	    return sysUserRoleMapper.findById(id);
	}

	/**
     * 根据条件分页查询用户角色关联列表
     *
     * @param sysUserRoleConditionEntity 用户角色关联信息
     * @return 用户角色关联集合
     */
	public ResponsePageEntity<SysUserRoleEntity> searchByPage(SysUserRoleConditionEntity sysUserRoleConditionEntity) {
		int count = sysUserRoleMapper.searchCount(sysUserRoleConditionEntity);
		if (count == 0) {
			return ResponsePageEntity.buildEmpty(sysUserRoleConditionEntity);
		}
		List<SysUserRoleEntity> dataList = sysUserRoleMapper.searchByCondition(sysUserRoleConditionEntity);
		return ResponsePageEntity.build(sysUserRoleConditionEntity, count, dataList);
	}

    /**
     * 新增用户角色关联
     *
     * @param sysUserRoleEntity 用户角色关联信息
     * @return 结果
     */
	public int insert(SysUserRoleEntity sysUserRoleEntity) {
	    return sysUserRoleMapper.insert(sysUserRoleEntity);
	}

	/**
     * 修改用户角色关联
     *
     * @param sysUserRoleEntity 用户角色关联信息
     * @return 结果
     */
	public int update(SysUserRoleEntity sysUserRoleEntity) {
	    return sysUserRoleMapper.update(sysUserRoleEntity);
	}

	/**
     * 批量删除用户角色关联对象
     *
     * @param ids 系统ID集合
     * @return 结果
     */
	public int deleteByIds(List<Long> ids) {
		List<SysUserRoleEntity> entities = sysUserRoleMapper.findByIds(ids);

		SysUserRoleEntity entity = new SysUserRoleEntity();
		return sysUserRoleMapper.deleteByIds(ids, entity);
	}

	@Override
	protected BaseMapper getBaseMapper() {
		return sysUserRoleMapper;
	}

}
